package com.lean.android.adsdk

import android.app.Activity
import android.view.LayoutInflater
import android.view.View

object DialogHelper {
    fun showVipDialog(
        activity: Activity,
        dialogLayoutRes: Int,
        onConfirm: (onTaskCompleted: () -> Unit) -> Unit,
        onCancel: () -> Unit = {}
    ) {
        val dialog = CustomDialog(activity)
        val view = LayoutInflater.from(activity).inflate(dialogLayoutRes, null)

        val must_confirm_any = view.findViewById<View>(R.id.must_confirm_any)
        val must_cancel_any = view.findViewById<View>(R.id.must_cancel_any)

        must_confirm_any?.onThrottleClick {
            onConfirm {
                dialog.dismiss()
            }
        }

        must_cancel_any?.onThrottleClick {
            dialog.dismiss()
            onCancel()
        }

        dialog.setCancelable(true)
        dialog.setCanceledOnTouchOutside(false)
        dialog.setContentView(view)

        if (!activity.isFinishing) {
            dialog.show()
        }
    }
}